package com.qtz.demo.service;

import com.qtz.demo.bean.Order;
import com.qtz.demo.mapper.OrderMapper;
import com.qtz.demo.util.RedisUtil;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Resource
    private RedisTemplate<String,Object> redisTemplate;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<Order> showAllOrders() {
        String str = "select * from orders";
        List<Order> list = (List<Order>)redisUtil.get(str);
        if(null==list) {
            System.out.println("从数据库中查找");
            list = orderMapper.showAllOrders();
            redisUtil.set(str,list);
        }
        System.out.println("从redis中查找");
        return list;
    }

    @Override
    public List<Order> showByUid(String uid) {
        List<Order> list = orderMapper.showByUid(uid);
        return list;
    }

    @Override
    public boolean addOrder(Order order) {
        return orderMapper.addOrder(order);
    }

    @Override
    public Order findByTime(String createtime) {
        return orderMapper.findByTime(createtime);
    }

    @Override
    public List<Order> showMyMakingOrder(String uid) {

        return orderMapper.showMyMakingOrder(uid);
    }

    @Override
    public boolean finishOrder(String oid) {
        return orderMapper.finishOrder(oid);
    }

    @Override
    public List<Order> showUndoOrder() {
        return orderMapper.showUndoOrder();
    }

}
